<template>
	<view class="content">
		<view class="input-group">
			<view class="input-row border">
				<view class="content-tab">
					<text class="title">昵</text>
					<text class="title">称</text>
				</view>
				<input type="text" v-model="name" placeholder="请输入昵称">
			</view>
			<view class="input-row border">
				<view class="content-tab">
					<text class="title">手</text>
					<text class="title">机</text>
					<text class="title">号</text>
				</view>
				<input type="text" v-model="account" placeholder="请输入手机号">
			</view>
			<view class="input-row border">
				<view class="content-tab">
					<text class="title">邮</text>
					<text class="title">箱</text>
				</view>
				<input type="text"  v-model="email" placeholder="请输入邮箱">
			</view>
			<view class="input-row border">
				<view class="content-tab">
					<text class="title">地</text>
					<text class="title">址</text>
				</view>
				<input type="text"  v-model="adress" placeholder="请输入收货地址">
			</view>
			<view class="input-row border">
				<view class="content-tab">
					<text class="title">密</text>
					<text class="title">码</text>
				</view>
				<input type="text" password="true" v-model="pwd" placeholder="请输入密码">
			</view>
			<view class="input-row">
				<text class="title">确认密码</text>
				<input type="text" password="true" v-model="repwd" placeholder="请输入确认密码">
			</view>
		</view>
		<view v-if="pwd!=repwd&&pwd!=''">
			<text style="color: red;">两次输入的密码不一致</text>
		</view>
		<view class="btn-row">
			<button :disabled="pwd!=repwd" type="primary" class="primary" @tap="bindRegister">注册</button>
		</view>		     
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: '',
				pwd: '',
				repwd: '',
				email:'',
				adress:'',
				name:''
			};
		},
		methods:{
			bindRegister(){
				const res= this.$myRequest({
					url:'/users/customer_register/',
					method:'POST',
					data:{
						'name':this.name,
						'phone':this.account,
						'address':this.adress,
						'email':this.email,
						"password":this.pwd
					}
				}).then((response)=>{
					// uni.showToast({
					// 	icon:"none",
					// 	title:"注册成功"
					// }); 
					if(response.data==='OK'){
						uni.showToast({
							icon:"none",
							title:"注册成功"
						}); 
						setTimeout(function(){
							uni.navigateBack({
								delta:1
							})
						},2000);
					}
					if(response.data==="用户已存在"){
						uni.showToast({
							icon:"none",
							title:"用户已存在"
						});
					}
				}).catch((error)=>{
					console.log('....');
				})
				
				// console.log('成功了');
				// uni.showToast({
				// 	icon:"none",
				// 	title:"注册成功"
				// }); 
				// setTimeout(function(){
				// 	uni.navigateBack({
				// 		delta:1
				// 	})
				// },2000)
				
				

			}
		}
	}
</script>

<style>
	@import '../../../common/denglu.css';
	
	.content-tab{
		display: flex;
		width: 4em;
		justify-content:space-between;
	}
	.input-row input{
		margin-left: 15upx;
	}
</style>
